//package com.yupi.springbootinit.controller;
//
//import com.yupi.springbootinit.config.RabbitMqConfig;
//import com.yupi.springbootinit.mq.EventEnvelope;
//import org.springframework.amqp.rabbit.core.RabbitTemplate;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.Map;
//import java.util.UUID;
//
//@RestController
//@RequestMapping("/internal/mq")
//public class MessageSmokeController {
//
//    private final RabbitTemplate rabbitTemplate;
//
//    public MessageSmokeController(RabbitTemplate rabbitTemplate) {
//        this.rabbitTemplate = rabbitTemplate;
//    }
//
//    @GetMapping("/smoke")
//    public Map<String, Object> smoke(@RequestParam(defaultValue = "10000") long delayMs) {
//        long now = System.currentTimeMillis();
//
//        // 即时消息
//        EventEnvelope immediate = new EventEnvelope(
//                UUID.randomUUID().toString(),
//                "order.created",
//                now,
//                RabbitMqConfig.RK_ORDER_CREATED,
//                Map.of("demo", true)
//        );
//        rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_DELAYED, RabbitMqConfig.RK_ORDER_CREATED, immediate);
//
//        // 延迟消息（x-delay）
//        EventEnvelope delayed = new EventEnvelope(
//                UUID.randomUUID().toString(),
//                "reminder.unclaimed",
//                now,
//                RabbitMqConfig.RK_REMINDER_UNCLAIMED,
//                Map.of("delayMs", delayMs)
//        );
//        rabbitTemplate.convertAndSend(
//                RabbitMqConfig.EXCHANGE_DELAYED,
//                RabbitMqConfig.RK_REMINDER_UNCLAIMED,
//                delayed,
//                msg -> { msg.getMessageProperties().setHeader("x-delay", (int) Math.min(delayMs, Integer.MAX_VALUE)); return msg; }
//        );
//
//        return Map.of("status", "ok", "delayMs", delayMs);
//    }
//}